<%
'******************************************************************************
' Copyright (C) 2006 Google Inc.
'  
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'  
'      http://www.apache.org/licenses/LICENSE-2.0
'  
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.
'******************************************************************************
%>
<!-- #include file="../library/googleglobal.asp" -->
<%

' Retrieve the XML received
Dim ResponseXml, biData, nIndex
biData = Request.BinaryRead(Request.TotalBytes)
For nIndex = 1 To LenB(biData)
	ResponseXml = ResponseXml & Chr(AscB(MidB(biData,nIndex,1)))
Next

LogMessage ResponseXml

Dim MyOrder
Set MyOrder = New Order

Dim ResponseNode, RootTag
Set ResponseNode = GetRootNode(ResponseXml)
RootTag = ResponseNode.Tagname

Select Case RootTag
	Case "new-order-notification"
		ProcessNewOrderNotification ResponseXml
	Case "order-state-change-notification"
		ProcessOrderStateChangeNotification ResponseXml
	Case "risk-information-notification"
		ProcessRiskInformationNotification ResponseXml
	Case "charge-amount-notification"
		ProcessChargeAmountNotification ResponseXml
	Case "chargeback-amount-notification"
		ProcessChargebackAmountNotification ResponseXml
	Case "refund-amount-notification"
		ProcessRefundAmountNotification ResponseXml
	Case "authorization-amount-notification"
		ProcessAuthorizationAmountNotification ResponseXml
	Case "merchant-calculation-callback"
		ProcessMerchantCalculationCallback ResponseXml
	Case Else
End Select 

' Handle a new-order-notifiation message
Sub ProcessNewOrderNotification(ResponseXml)

	Dim MyNewOrder
	Set MyNewOrder = New NewOrderNotification
	MyNewOrder.ParseNotification ResponseXml

	' ********** How to access NewOrderNotification variables **********
	' ***************************** BEGIN ******************************

	DoSomethingWith MyNewOrder.TimeStamp
	DoSomethingWith MyNewOrder.GoogleOrderNumber
	DoSomethingWith MyNewOrder.ShippingName
	DoSomethingWith MyNewOrder.ShippingCost
	DoSomethingWith MyNewOrder.BuyerId
	DoSomethingWith MyNewOrder.MerCalcSuccessful
	DoSomethingWith MyNewOrder.FulfillmentOrderState
	DoSomethingWith MyNewOrder.FinancialOrderState
	DoSomethingWith MyNewOrder.AdjustmentTotal
	DoSomethingWith MyNewOrder.TaxTotal
	DoSomethingWith MyNewOrder.OrderTotal
	DoSomethingWith MyNewOrder.MarketingEmailAllowed

	Dim MyItem
	For Each MyItem In MyNewOrder.ItemArr
		DoSomethingWith MyItem.Name
		DoSomethingWith MyItem.Description
		DoSomethingWith MyItem.Quantity
		DoSomethingWith MyItem.UnitPrice
		DoSomethingWith MyItem.MerchantItemId
		DoSomethingWith MyItem.TaxTableSelector

		If IsObject(MyItem.MerchantPrivateItemData) Then
			Dim MyPrivateItemData
			Set MyPrivateItemData = MyItem.MerchantPrivateItemData
			' Retrieve <color> and <weight> values
			DoSomethingWith GetElementText(MyPrivateItemData, "color")
			DoSomethingWith GetElementText(MyPrivateItemData, "weight")
			' Or get the raw <merchant-private-item-data> XML
			' DoSomethingWith MyPrivateItemData.xml
			Set MyPrivateItemData = Nothing
		End If
	Next

	If IsObject(MyNewOrder.MerchantPrivateData) Then
		Dim MyPrivateData
		Set MyPrivateData = MyNewOrder.MerchantPrivateData
		DoSomethingWith GetElementText(MyPrivateData, "session-id")
		' Or get the raw <merchant-private-data> XML
		DoSomethingWith MyPrivateData.xml
		Set MyPrivateData = Nothing
	End If

	Dim BillingAddress
	Set BillingAddress = MyNewOrder.BuyerBillingAddress
	DoSomethingWith BillingAddress.ID
	DoSomethingWith BillingAddress.ContactName
	DoSomethingWith BillingAddress.CompanyName
	DoSomethingWith BillingAddress.Address1
	DoSomethingWith BillingAddress.Address2
	DoSomethingWith BillingAddress.City
	DoSomethingWith BillingAddress.Region
	DoSomethingWith BillingAddress.PostalCode
	DoSomethingWith BillingAddress.CountryCode
	DoSomethingWith BillingAddress.Email
	DoSomethingWith BillingAddress.Phone
	DoSomethingWith BillingAddress.Fax
	Set BillingAddress = Nothing

	Dim ShippingAddress
	Set ShippingAddress = MyNewOrder.BuyerShippingAddress
	DoSomethingWith ShippingAddress.ID
	DoSomethingWith ShippingAddress.ContactName
	DoSomethingWith ShippingAddress.CompanyName
	DoSomethingWith ShippingAddress.Address1
	DoSomethingWith ShippingAddress.Address2
	DoSomethingWith ShippingAddress.City
	DoSomethingWith ShippingAddress.Region
	DoSomethingWith ShippingAddress.PostalCode
	DoSomethingWith ShippingAddress.CountryCode
	DoSomethingWith ShippingAddress.Email
	DoSomethingWith ShippingAddress.Phone
	DoSomethingWith ShippingAddress.Fax
	Set ShippingAddress = Nothing

	If MyNewOrder.CouponIndex >= 0 Then
		Dim MyCoupon
		For Each MyCoupon In MyNewOrder.CouponArr
			DoSomethingWith MyCoupon.Code
			DoSomethingWith MyCoupon.AppliedAmount
			DoSomethingWith MyCoupon.CalculatedAmount
			DoSomethingWith MyCoupon.Message
		Next
	End If

	If MyNewOrder.GiftCertIndex >= 0 Then
		Dim MyGiftCert
		For Each MyGiftCert In MyNewOrder.GiftCertArr
			DoSomethingWith MyGiftCert.Code
			DoSomethingWith MyGiftCert.AppliedAmount
			DoSomethingWith MyGiftCert.CalculatedAmount
			DoSomethingWith MyGiftCert.Message
		Next
	End If

	If IsObject(MyNewOrder.FlatRateShippingAdjustment) Then
		Dim FlatRateShippingAdjustment
		Set FlatRateShippingAdjustment = MyNewOrder.FlatRateShippingAdjustment
		DoSomethingWith FlatRateShippingAdjustment.ShippingName
		DoSomethingWith FlatRateShippingAdjustment.ShippingCost
		Set FlatRateShippingAdjustment = Nothing
	End If

	If IsObject(MyNewOrder.MerchantCalculatedShippingAdjustment) Then
		Dim MerchantCalculatedShippingAdjustment
		Set MerchantCalculatedShippingAdjustment = MyNewOrder.MerchantCalculatedShippingAdjustment
		DoSomethingWith MerchantCalculatedShippingAdjustment.ShippingName
		DoSomethingWith MerchantCalculatedShippingAdjustment.ShippingCost
		Set MerchantCalculatedShippingAdjustment = Nothing
	End If

	If IsObject(MyNewOrder.CarrierCalculatedShippingAdjustment) Then
		Dim CarrierCalculatedShippingAdjustment
		Set CarrierCalculatedShippingAdjustment = MyNewOrder.CarrierCalculatedShippingAdjustment
		DoSomethingWith CarrierCalculatedShippingAdjustment.ShippingName
		DoSomethingWith CarrierCalculatedShippingAdjustment.ShippingCost
		Set CarrierCalculatedShippingAdjustment = Nothing
	End If

	If IsObject(MyNewOrder.PickupShippingAdjustment) Then
		Dim PickupShippingAdjustment
		Set PickupShippingAdjustment = MyNewOrder.PickupShippingAdjustment
		DoSomethingWith PickupShippingAdjustment.ShippingName
		DoSomethingWith PickupShippingAdjustment.ShippingCost
		Set PickupShippingAdjustment = Nothing
	End If

	' ***************************** END ******************************

	SendAck
End Sub

' Handle a order-state-change-notification message
Sub ProcessOrderStateChangeNotification(ResponseXml)

	Dim MyOrderState
	Set MyOrderState = New OrderStateChangeNotification
	MyOrderState.ParseNotification ResponseXml

	' ******** How to access OrderStateChangeNotification variables ********
	' ****************************** BEGIN *********************************

	DoSomethingWith MyOrderState.TimeStamp
	DoSomethingWith MyOrderState.GoogleOrderNumber
	DoSomethingWith MyOrderState.NewFulfillmentOrderState
	DoSomethingWith MyOrderState.NewFinancialOrderState
	DoSomethingWith MyOrderState.PreviousFulfillmentOrderState
	DoSomethingWith MyOrderState.PreviousFinancialOrderState

	' ****************************** END *********************************

	Dim GoogleOrderNumber, Amount, Reason, Comment
	Dim MerchantOrderNumber, Carrier, TrackingNumber, Mesage

	GoogleOrderNumber = MyOrderState.GoogleOrderNumber

	' Possible list of Order Processing commands

	' Financial Commands:

	' MyOrder.ChargeOrder GoogleOrderNumber, Amount
	' MyOrder.SendOrderCommand

	' MyOrder.RefundOrder GoogleOrderNumber, Reason, Amount, Comment
	' MyOrder.SendOrderCommand

	' MyOrder.CancelOrder GoogleOrderNumber, Reason, Comment
	' MyOrder.SendOrderCommand

	' MyOrder.AuthorizeOrder GoogleOrderNumber
	' MyOrder.SendOrderCommand

	' Fulfillment Commands:

	' MyOrder.ProcessOrder GoogleOrderNumber
	' MyOrder.SendOrderCommand

	' MyOrder.AddMerchantOrderNumber GoogleOrderNumber, MerchantOrderNumber
	' MyOrder.SendOrderCommand

	' MyOrder.DeliverOrder GoogleOrderNumber, Carrier, TrackingNumber, True
	' MyOrder.SendOrderCommand

	' MyOrder.AddTrackingData GoogleOrderNumber, Carrier, TrackingNumber
	' MyOrder.SendOrderCommand
	
	' MyOrder.SendBuyerMessage GoogleOrderNumber, Mesage, True
	' MyOrder.SendOrderCommand


	' Line-item Shipping Commands:

	' Dim ItemIds
	' ItemIds = Array("Item#1", "Item#3")

	' MyOrder.BackOrderItems GoogleOrderNumber, ItemIds, True
	' MyOrder.SendOrderCommand

	' MyOrder.CancelItems GoogleOrderNumber, ItemIds, Reason, Comment, True
	' MyOrder.SendOrderCommand

	' MyOrder.ReturnItems GoogleOrderNumber, ItemIds, True
	' MyOrder.SendOrderCommand

	' MyOrder.ResetItemsShippingInfo GoogleOrderNumber, ItemIds, True
	' MyOrder.SendOrderCommand


    ' <ship-items> command:

	' Dim MyItemShippingInfoList
	' Set MyItemShippingInfoList = New ItemShippingInfoList

	' Dim MyItemShippingInfo
	' Set MyItemShippingInfo = New ItemShippingInfo
	' MyItemShippingInfo.ItemId = "Item#1"
	' MyItemShippingInfo.AddTrackingData "UPS", "UPS1111"
	' MyItemShippingInfo.AddTrackingData "FedEx", "FedEx1111"
	' MyItemShippingInfoList.AddItemShippingInfo MyItemShippingInfo
	' Set MyItemShippingInfo = Nothing

	' Set MyItemShippingInfo = New ItemShippingInfo
	' MyItemShippingInfo.ItemId = "Item#2"
	' MyItemShippingInfo.AddTrackingData "UPS", "UPS2222"
	' MyItemShippingInfo.AddTrackingData "FedEx", "FedEx2222"
	' MyItemShippingInfoList.AddItemShippingInfo MyItemShippingInfo
	' Set MyItemShippingInfo = Nothing

	' MyOrder.ShipItems GoogleOrderNumber, MyItemShippingInfoList, True
	' MyOrder.SendOrderCommand

	' Set MyItemShippingInfoList = Nothing


	' Archiving Commands:

	' MyOrder.ArchiveOrder GoogleOrderNumber
	' MyOrder.SendOrderCommand

	' MyOrder.UnarchiveOrder GoogleOrderNumber
	' MyOrder.SendOrderCommand


	Select Case MyOrderState.NewFinancialOrderState
		Case "REVIEWING"

		Case "CHARGEABLE"
			' MyOrder.ProcessOrder GoogleOrderNumber
			' MyOrder.SendOrderCommand

			' MyOrder.AuthorizeOrder GoogleOrderNumber
			' MyOrder.SendOrderCommand

			' MyOrder.ChargeOrder GoogleOrderNumber, ""
			' MyOrder.SendOrderCommand

			' MyOrder.CancelOrder GoogleOrderNumber, Reason, Comment
			' MyOrder.SendOrderCommand

		Case "CHARGING"

		Case "CHARGED"
			' MyOrder.AddTrackingData GoogleOrderNumber, Carrier, TrackingNumber
			' MyOrder.SendOrderCommand

			' MyOrder.DeliverOrder GoogleOrderNumber, Carrier, TrackingNumber, True
			' MyOrder.SendOrderCommand

			' MyOrder.RefundOrder GoogleOrderNumber, Reason, Amount, Comment
			' MyOrder.SendOrderCommand

		Case "PAYMENT_DECLINED"
			' MyOrder.CancelOrder GoogleOrderNumber, Reason, Comment
			' MyOrder.SendOrderCommand

		Case "CANCELLED"

		Case "CANCELLED_BY_GOOGLE"
			' MyOrder.SendBuyerMessage GoogleOrderNumber, Mesage, true
			' MyOrder.SendOrderCommand

		Case Else
	End Select

	Select Case MyOrderState.NewFulfillmentOrderState
		Case "NEW"

		Case "PROCESSING"

		Case "DELIVERED"
			' MyOrder.ArchiveOrder GoogleOrderNumber
			' MyOrder.SendOrderCommand

		Case "WILL_NOT_DELIVER"

		Case Else
	End Select


	SendAck
End Sub

' Handle a risk-information-notification message
Sub ProcessRiskInformationNotification(ResponseXml)

	Dim MyRiskInfo
	Set MyRiskInfo = New RiskInformationNotification
	MyRiskInfo.ParseNotification ResponseXml

	' ******** How to access RiskInformationNotification variables *********
	' ****************************** BEGIN *********************************

	DoSomethingWith MyRiskInfo.TimeStamp
	DoSomethingWith MyRiskInfo.GoogleOrderNumber
	DoSomethingWith MyRiskInfo.IpAddress
	DoSomethingWith MyRiskInfo.EligibleForProtection
	DoSomethingWith MyRiskInfo.AvsResponse
	DoSomethingWith MyRiskInfo.CvnResponse
	DoSomethingWith MyRiskInfo.PartialCC
	DoSomethingWith MyRiskInfo.BuyerAccountAge

	Dim BillingAddress
	Set BillingAddress = MyRiskInfo.BillingAddress
	DoSomethingWith BillingAddress.ID
	DoSomethingWith BillingAddress.ContactName
	DoSomethingWith BillingAddress.CompanyName
	DoSomethingWith BillingAddress.Address1
	DoSomethingWith BillingAddress.Address2
	DoSomethingWith BillingAddress.City
	DoSomethingWith BillingAddress.Region
	DoSomethingWith BillingAddress.PostalCode
	DoSomethingWith BillingAddress.CountryCode
	DoSomethingWith BillingAddress.Email
	DoSomethingWith BillingAddress.Phone
	DoSomethingWith BillingAddress.Fax
	Set BillingAddress = Nothing

	' ****************************** END *********************************

	SendAck
End Sub

' Handle a charge-amount-notification message
Sub ProcessChargeAmountNotification(ResponseXml)

	Dim MyChargeAmountNot
	Set MyChargeAmountNot = New ChargeAmountNotification
	MyChargeAmountNot.ParseNotification ResponseXml

	' ********** How to access ChargeAmountNotification variables **********
	' ****************************** BEGIN *********************************
	DoSomethingWith MyChargeAmountNot.TimeStamp
	DoSomethingWith MyChargeAmountNot.GoogleOrderNumber
	DoSomethingWith MyChargeAmountNot.LatestChargeAmount
	DoSomethingWith MyChargeAmountNot.TotalChargeAmount
	' ****************************** END *********************************

	SendAck
End Sub

' Handle a chargeback-amount-notification message
Sub ProcessChargebackAmountNotification(ResponseXml)

	Dim MyChargebackAmountNot
	Set MyChargebackAmountNot = New ChargebackAmountNotification
	MyChargebackAmountNot.ParseNotification ResponseXml

	' ******* How to access ChargebackAmountNotification variables ********
	' ****************************** BEGIN ********************************
	DoSomethingWith MyChargebackAmountNot.TimeStamp
	DoSomethingWith MyChargebackAmountNot.GoogleOrderNumber
	DoSomethingWith MyChargebackAmountNot.LatestChargebackAmount
	DoSomethingWith MyChargebackAmountNot.TotalChargebackAmount
	' ****************************** END *********************************

	SendAck
End Sub

' Handle a refund-amount-notification message
Sub ProcessRefundAmountNotification(ResponseXml)

	Dim MyRefundAmountNot
	Set MyRefundAmountNot = New RefundAmountNotification
	MyRefundAmountNot.ParseNotification ResponseXml

	' ********* How to access RefundAmountNotification variables **********
	' ****************************** BEGIN ********************************
	DoSomethingWith MyRefundAmountNot.TimeStamp
	DoSomethingWith MyRefundAmountNot.GoogleOrderNumber
	DoSomethingWith MyRefundAmountNot.LatestRefundAmount
	DoSomethingWith MyRefundAmountNot.TotalRefundAmount
	' ****************************** END ********************************

	SendAck
End Sub

' Handle an authorization-amount-notification message
Sub ProcessAuthorizationAmountNotification(ResponseXml)

	Dim MyAuthAmountNot
	Set MyAuthAmountNot = New AuthorizationAmountNotification
	MyAuthAmountNot.ParseNotification ResponseXml

	' ****** How to access AuthorizationAmountNotification variables *******
	' ****************************** BEGIN *********************************
	DoSomethingWith MyAuthAmountNot.TimeStamp
	DoSomethingWith MyAuthAmountNot.GoogleOrderNumber
	DoSomethingWith MyAuthAmountNot.AvsResponse
	DoSomethingWith MyAuthAmountNot.CvnResponse
	DoSomethingWith MyAuthAmountNot.AuthorizationAmount
	DoSomethingWith MyAuthAmountNot.AuthorizationExpirationDate
	' ******************************* END *********************************

	SendAck
End Sub

' Acknowledge the notification by responding to Google Checkout 
' with <notification-acknowledgment>.
Public Sub SendAck()
	Dim XmlAcknowledgment
	XmlAcknowledgment = "<?xml version=""1.0"" encoding=""UTF-8""?><notification-acknowledgment xmlns=""http://checkout.google.com/schema/2"" />"
	Response.Write XmlAcknowledgment
	LogMessage XmlAcknowledgment
End Sub

' Handle merchant-calculation-callback message and 
' Respond with merchant-calculation-results message
Sub ProcessMerchantCalculationCallback(ResponseXml)

	Dim MyMerCalcCallback
	Set MyMerCalcCallback = New MerchantCalculationCallback
	MyMerCalcCallback.ParseNotification ResponseXml

	' ********* How to access MerchantCalculationCallback variables *********
	' ****************************** BEGIN **********************************
	Dim MyItem
	For Each MyItem In MyMerCalcCallback.ItemArr
		DoSomethingWith MyItem.Name
		DoSomethingWith MyItem.Description
		DoSomethingWith MyItem.Quantity
		DoSomethingWith MyItem.UnitPrice
		DoSomethingWith MyItem.MerchantItemId
		DoSomethingWith MyItem.TaxTableSelector

		If IsObject(MyItem.MerchantPrivateItemData) Then
			Dim MyPrivateItemData
			Set MyPrivateItemData = MyItem.MerchantPrivateItemData
			' Retrieve <color> and <weight> values
			DoSomethingWith GetElementText(MyPrivateItemData, "color")
			DoSomethingWith GetElementText(MyPrivateItemData, "weight")
			' Or get the raw <merchant-private-item-data> XML
			' DoSomethingWith MyPrivateItemData.xml
			Set MyPrivateItemData = Nothing
		End If
	Next

	If IsObject(MyMerCalcCallback.MerchantPrivateData) Then
		Dim MyPrivateData
		Set MyPrivateData = MyMerCalcCallback.MerchantPrivateData
		' Retrieve <session-id>
		DoSomethingWith GetElementText(MyPrivateData, "session-id")
		' Or get the raw <merchant-private-data> XML
		' DoSomethingWith MyPrivateData.xml
		Set MyPrivateData = Nothing
	End If

	DoSomethingWith MyMerCalcCallback.CartExpirationDate
	DoSomethingWith MyMerCalcCallback.BuyerId
	DoSomethingWith MyMerCalcCallback.BuyerLanguage
	DoSomethingWith MyMerCalcCallback.Tax

	If MyMerCalcCallback.AnonymousAddressIndex >= 0 Then
		Dim AnonymousAddress
		For Each AnonymousAddress In MyMerCalcCallback.AnonymousAddressArr
			DoSomethingWith AnonymousAddress.ID
			DoSomethingWith AnonymousAddress.ContactName
			DoSomethingWith AnonymousAddress.CompanyName
			DoSomethingWith AnonymousAddress.Address1
			DoSomethingWith AnonymousAddress.Address2
			DoSomethingWith AnonymousAddress.City
			DoSomethingWith AnonymousAddress.Region
			DoSomethingWith AnonymousAddress.PostalCode
			DoSomethingWith AnonymousAddress.CountryCode
			DoSomethingWith AnonymousAddress.Email
			DoSomethingWith AnonymousAddress.Phone
			DoSomethingWith AnonymousAddress.Fax
		Next
	End If

	If MyMerCalcCallback.MerchantCodeIndex >= 0 Then
		Dim MerchantCode
		For Each MerchantCode In MyMerCalcCallback.MerchantCodeArr
			DoSomethingWith MerchantCode
		Next
	End If

	If MyMerCalcCallback.ShippingMethodIndex >= 0 Then
		Dim ShippingMethod
		For Each ShippingMethod In MyMerCalcCallback.ShippingMethodArr
			DoSomethingWith ShippingMethod
		Next
	End If

	' ****************************** END **********************************

	' Construct <merchant-calculation-results>
	Dim MyMerCalcResults, MyResult, MyCoupon, MyGiftCert, MerchantCodeType
	Set MyMerCalcResults = New MerchantCalculationResults

	' Loop through each anonymous address from the callback
	For Each AnonymousAddress In MyMerCalcCallback.AnonymousAddressArr

		' Construct and add <result> into <merchant-calculation-results>

		' Loop through each merchant-calculated-shipping method
		If MyMerCalcCallback.ShippingMethodIndex >= 0 Then
			For Each ShippingMethod In MyMerCalcCallback.ShippingMethodArr
				Set MyResult = New Result

				' Get the shipping name, rate and whether it's shippable
				MyResult.ShippingName = ShippingMethod
				MyResult.ShippingRate = 8
				MyResult.Shippable = True

				' Anonymous-address ID
				MyResult.AddressId = AnonymousAddress.ID

				' Calculate merchnat-calculated tax
				If MyMerCalcCallback.Tax = "true" Then
					MyResult.TotalTax = 5
				End If

				' Validate coupons and gift certificates
				If MyMerCalcCallback.MerchantCodeIndex >= 0 Then
					For Each MerchantCode In MyMerCalcCallback.MerchantCodeArr

						' Determine whether the code is a Coupon or GiftCert
						MerchantCodeType = "Coupon"

						' Create Coupon result
						If MerchantCodeType = "Coupon" Then
							Set MyCoupon = New CouponResult
							MyCoupon.Code = MerchantCode
							MyCoupon.Valid = True
							MyCoupon.Amount = 10
							MyCoupon.Message = "Your coupon has been applied successfully."
							MyResult.AddCouponResult MyCoupon
							Set MyCoupon = Nothing

						' Create GiftCert result
						ElseIf MerchantCodeType = "GiftCert" Then
							Set MyGiftCert = New GiftCertResult
							MyGiftCert.Code = MerchantCode
							MyGiftCert.Valid = True
							MyGiftCert.Amount = 10
							MyGiftCert.Message = "You gift certificate has been applied successfully."
							MyResult.AddGiftCertResult MyGiftCert
							Set MyGiftCert = Nothing
						End If
					Next
				End If

				' Add this <result> to <merchant-calculation-results>
				MyMerCalcResults.AddResult MyResult
				Set MyResult = Nothing
			Next

		' No merchant-calculated-shipping methods
		Else

			Set MyResult = New Result

			' Specify whether it's shippable
			MyResult.Shippable = True
			
			' Anonymous-address ID
			MyResult.AddressId = AnonymousAddress.ID

			' Calculate merchnat-calculated tax
			If MyMerCalcCallback.Tax = "true" Then
				MyResult.TotalTax = 5.00
			End If

			' Validate coupons and gift certificates
			If MyMerCalcCallback.MerchantCodeIndex >= 0 Then
				For Each MerchantCode In MyMerCalcCallback.MerchantCodeArr

					' Determine whether the code is a Coupon or GiftCert
					MerchantCodeType = "Coupon"

					' Create Coupon result
					If MerchantCodeType = "Coupon" Then
						Set MyCoupon = New CouponResult
						MyCoupon.Code = MerchantCode
						MyCoupon.Valid = True
						MyCoupon.Amount = 10
						MyCoupon.Message = "Your coupon has been applied successfully."
						MyResult.AddCouponResult MyCoupon
						Set MyCoupon = Nothing

					' Create GiftCert result
					ElseIf MerchantCodeType = "GiftCert" Then
						Set MyGiftCert = New GiftCertResult
						MyGiftCert.Code = MerchantCode
						MyGiftCert.Valid = True
						MyGiftCert.Amount = 15
						MyGiftCert.Message = "You gift certificate has been applied successfully."
						MyResult.AddGiftCertResult MyGiftCert
						Set MyGiftCert = Nothing
					End If
				Next
			End If

			' Add this <result> to <merchant-calculation-results>
			MyMerCalcResults.AddResult MyResult
			Set MyResult = Nothing
		End If
	Next

	' Respond to Google with <merchant-calculation-results>
	Dim MyMerCalcResultsXml
	MyMerCalcResultsXml = MyMerCalcResults.GetXml
	Response.Write MyMerCalcResultsXml

	LogMessage MyMerCalcResultsXml

	Set MyMerCalcCallback = Nothing
	Set MyMerCalcResults = Nothing
End Sub


Set MyOrder = Nothing


' DoSomethingWith is a dummy function that demonstrates how you can access 
'     each variable from a notification/callback class once it's parsed through.
' Any calls to this function should be removed from the code.
Sub DoSomethingWith(Variable)
  ' Do nothing 
End Sub

%>